package com.jian.sys.common;

import java.util.ArrayList;
import java.util.List;

/**
 * 分层 菜单节点
 * 吧没有层级关系的变成层级关系
 */
public class TreeNodeBuilder {
    public static List<TreeNode> build(List<TreeNode> treeNode,Integer topPid){
        List<TreeNode> nodes= new ArrayList<>();
        for (TreeNode n1:treeNode) {
            if(n1.getPid()==topPid){
                nodes.add(n1);
            }
            for(TreeNode n2:treeNode){
                if(n1.getId()==n2.getPid()){
                    n1.getChildren().add(n2);
                }
            }
        }
        return  nodes;
    }
}
